home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / misc / contrib / ifman next >
Encoding:
Text File  |  1994-03-13  |  4.2 KB  |  170 lines

  1. #! /usr/bin/perl
  2. #
  3. # This is a utility script to manipulate Fidonet-related issues
  4. # using Eugene Crosser's ifmail package
  5. #
  6. # Version 0.1
  7. #
  8. # (C) Michael Bravo and The Communication Tube, 1994
  9. #
  10. # You can do whatever you want with this script. I take no responsibility
  11. # whatsoever in anything related to this script. If you make some useful
  12. # additions to this, please think of sending them to me so I could partake
  13. # of your wisdom.
  14. #
  15. # This script was written to help attaching and requesting files from the
  16. # commandline, much like you do with Squish under DOS or OS/2. It is certainly
  17. # not perfect - I used it as an exercise in Perl. It also probably lacks
  18. # some other useful features, like ability to specify trunc/sent or kill/sent
  19. # attributes etc etc. If you really want this or some other features 
  20. # implemented, write me at mbravo@tctube.spb.su or mbravo@octopus.spb.su
  21. # and I will try to do what I can.
  22. #
  23. # Note - files don't get copied to any spool dir, so if you move attached
  24. # files somewhere, they won't get sent.
  25. #
  26. # This script is supposed to read ifmail's config to determine where outbound
  27. # directory and logfile are. The only two parameters to modify in most cases
  28. # are below.
  29.  
  30. $cfgfile="/usr/local/lib/fnet/config";     # where the config is
  31. $ifowner="uucp";                           # who is the owner of the ifmail
  32.  
  33. if ( getpwuid($<) ne $ifowner ) { print "You must be owner of ifmail\n"; exit 1; }
  34.  
  35. if ( (@ARGV < 3) || $ARGV[0] eq "-?" || $ARGV[0] eq "-h" ) {
  36.     &usage;
  37.  
  38. $ARGV[0] =~ tr/A-Z/a-z/;
  39. $ARGV[3] =~ tr/A-Z/a-z/;
  40.  
  41. &parsecfg;
  42.  
  43. if ( $logfile ne "" ) { 
  44.     open(LOG, ">>".$logfile) || die "Can't open logfile";
  45. }
  46.  
  47. if (substr($ARGV[1], 0, 1) ne "/") {
  48.     $cwd=`pwd`;
  49.     chop $cwd;
  50.     $ARGV[1] = $cwd."/".$ARGV[1];
  51. }
  52.  
  53. if ($ARGV[3] eq "" || $ARGV[3] eq "normal") {
  54.     $flavour = 'f';
  55. } elsif ($ARGV[3] eq "crash") {
  56.     $flavour = 'c';
  57. } elsif ($ARGV[3] eq "hold") {
  58.     $flavour = 'h';
  59. } else {
  60.     print "Unknown flavour, assuming normal\n";
  61.     $flavour = 'f';
  62. }
  63.  
  64. if ($ARGV[0] eq "send") {
  65.     &attach($ARGV[1], $ARGV[2]);
  66. } elsif ($ARGV[0] eq "get") {
  67.     &request($ARGV[1], $ARGV[2]);
  68. } else {
  69.     print "Unknown command, try ifman -h\n";
  70.     exit 1;
  71. }
  72.  
  73. close(LOG);
  74.  
  75. exit 0;
  76.  
  77. #######################################################################
  78.  
  79. sub attach {
  80.     local($fspec, $address) = @_;
  81.  
  82.     $floname = &resolve($address);
  83.  
  84.     open(FLO, ">>".$outbound."/".$floname) || die "Can't open flo-file $outbound/$floname";
  85.     open(FIND, "find $fspec -print |") || die "Can't generate list of files"; 
  86.  
  87.     if ( eof(FIND) ) {
  88.         print "No matching files, nothing to send\n";
  89.         exit 1;
  90.     }
  91.  
  92.     while (<FIND>) {
  93.  
  94.         chop;
  95.         $datestamp = `date \"+%D %T\"`;
  96.         chop $datestamp;
  97.         printf LOG "%s %s %s\n", $datestamp, $$, "ifman: sending $_ to $address";
  98.         printf FLO "%s\n", $_;    
  99.     }
  100.  
  101.     close(FLO);
  102.     close(FIND);
  103. }
  104.  
  105. sub request {
  106.     local($fspec, $address) = @_;
  107.  
  108.     $reqname = &resolve($address);
  109.  
  110.     $reqname =~ s/\.[fch]lo/\.req/;
  111.     
  112.     open(REQ, ">>".$outbound."/".$reqname) || die "Can't open req-file";
  113.  
  114.     $datestamp = `date \"+%D %T\"`;
  115.     chop $datestamp;
  116.     printf LOG "%s %s %s\n", $datestamp, $$, "ifman: requesting $fspec from $address";
  117.     printf REQ "%s\n", $fspec;    
  118.  
  119.     close(REQ);
  120. }
  121.  
  122. sub resolve {
  123.     local($addr) = @_;
  124.  
  125.     if ( index($addr, ":") >=0 ) {
  126.         print "I cannot resolve addresses with zones!\n";
  127.         exit 1;
  128.     } elsif ( index($addr, "/") == -1 ) {
  129.         print "Not a valid address!\n";
  130.         exit 1;
  131.     }
  132.  
  133.     ($net, $node, $point) = split(/\/|\./, $addr); 
  134.  
  135.     if ( defined $point ) {
  136.         $pointdir = sprintf("%04x%04x.pnt", $net, $node);
  137.         if ( ! -e $outbound."/".$pointdir ) {
  138.             mkdir ($outbound."/".$pointdir, 0755) || die "Can't create point directory";
  139.         }
  140.         $flo = sprintf("0000%04x.%01slo", $point, $flavour);
  141.         return $pointdir."/".$flo;
  142.     } else {
  143.         $flo = sprintf("%04x%04x.%01slo", $net, $node, $flavour);
  144.         return $flo;
  145.     }
  146. }
  147.  
  148. sub usage {
  149.     print "ifmail manager script\n";
  150.     print "usage: ifman <cmd> <filespec> <address> [flavour]\n";
  151.     print "  commands: send, get\n";
  152.     print "  flavours: normal, crash, hold. Default is normal.\n";
  153.     print "Only 2d addresses with points are supported - no zones!\n";
  154.     exit 1;
  155. }
  156.  
  157. sub parsecfg {
  158.     open(CFG, $cfgfile) || die "Can't open ifmail config file";
  159.  
  160.     while (<CFG>) {
  161.         chop;
  162.         if (/^#/) { next; }
  163.         if (/^outbound\s+(\S+)/) { $outbound = $1; }
  164.         if (/^logfile\s+(\S+)/) { $logfile = $1; }
  165.     }
  166.     
  167.     close(CFG);
  168. }
  169.